//
//  ViewController.m
//  control
//
//  Created by student on 16/2/18.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UIImage *img1 = [UIImage imageNamed:@"whiteButton"];
    UIImage *img2 = [UIImage imageNamed:@"blueButton"];
    UIEdgeInsets insets = UIEdgeInsetsMake(0, 12, 0, 12);
    UIImage *img3 = [img1 resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
    UIImage *img4 = [img2 resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
    [self.DoSthBtn setBackgroundImage:img3 forState:UIControlStateNormal];
    [self.DoSthBtn setBackgroundImage:img4 forState:UIControlStateHighlighted];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)backTap:(id)sender
{
    // 两种方法
    // 1. 结束编辑
        [self.view endEditing:YES];
    
//    // 2. 取消第一响应者
//    [self.nameTextField resignFirstResponder];
//    [self.phoneTextField resignFirstResponder];
//    
}

- (IBAction)SegementChanged:(UISegmentedControl *)sender
{
    if (sender.selectedSegmentIndex == 0)
    {
        self.LeftSwitch.hidden = NO;
        self.RightSwitch.hidden = NO;
        self.DoSthBtn.hidden = YES;
    }
    else
    {
        self.LeftSwitch.hidden = YES;
        self.RightSwitch.hidden = YES;
        self.DoSthBtn.hidden = NO;

    }
}

- (IBAction)SwitchChanged:(UISwitch *)sender
{
    BOOL open = sender.on;
    [self.LeftSwitch setOn:open animated:YES];
    [self.RightSwitch setOn:open animated:YES];
}

- (IBAction)DoSthBtnPressed:(id)sender
{
    NSLog(@"%@",self.phoneTextField.text);
//   NSLog(@"%@",self.nameTextField.text);
    UIActionSheet *sheet = [[UIActionSheet alloc]initWithTitle:@"你确定吗？" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"是的，我确定！" otherButtonTitles: nil];
    [sheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex NS_DEPRECATED_IOS(2_0, 8_3) __TVOS_PROHIBITED
{


    if(buttonIndex == actionSheet.destructiveButtonIndex)
    {
        
        NSString *message = [NSString stringWithFormat:@"%@,放轻松！",self.nameTextField.text];
        UIAlertView *alertview = [[UIAlertView alloc]initWithTitle:@"某些事被执行了" message:message delegate:self cancelButtonTitle:@"欧耶" otherButtonTitles: nil];
        [alertview show];
    }
}

- (IBAction)SliderChanged:(UISlider *)sender
{
    int value = sender.value;
    NSLog(@"%f",sender.value);
    self.SlideLabel.text = [NSString stringWithFormat:@"%d",value];
}
@end
